import json

import pandas as pd
import requests
from tqdm import tqdm

df = pd.read_excel(".vscode/高情商沟通/intent_tag.xlsx")

dataset_id = "504b449f-c854-4342-9fc0-7fdeec94c961"
document_id = "4eb46d0e-63df-4682-ae87-b403f3d1782a"

url = f"http://39.105.167.2:5001/v1/datasets/{dataset_id}/documents/{document_id}/segments"

headers = {
    "Authorization": "Bearer dataset-vOmm8I2jZ1jeWpoIoQQBlOxl",
    "Content-Type": "application/json",
}

for _, row in tqdm(df.iterrows(), total=len(df)):
    data = {
        "segments": [
            {
                "content": row["userinput"],
                "answer": json.dumps(
                    {
                        "user_input": row["userinput"],
                        "tag": row["人设标签"],
                        "tone": row["语气"],
                        "style": row["风格"],
                        "detail_tag": row["详细标签"],
                        "content_tag": row["内容标签"],
                    },
                    ensure_ascii=False,
                ),
                "keywords": [
                    row["人设标签"],
                ],
            }
        ]
    }

    response = requests.post(
        url, headers=headers, data=json.dumps(data, ensure_ascii=False)
    )
